FROM centos:7

MAINTAINER Yang <yangyufans@qq.com>

ENV ZOOKEEPER_VERSION=3.4.13

RUN yum install -y wget java-1.8.0-openjdk.x86_64

RUN cd / && wget http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-$ZOOKEEPER_VERSION/zookeeper-$ZOOKEEPER_VERSION.tar.gz \
 && tar -zxvf zookeeper-$ZOOKEEPER_VERSION.tar.gz \
 && rm -rf zookeeper-$ZOOKEEPER_VERSION.tar.gz \
 && mv zookeeper-$ZOOKEEPER_VERSION zookeeper

RUN mkdir /data /dataLogs /logs

RUN echo "ZONE=Asia/Shanghai" > /etc/sysconfig/clock && \
    rm -rf /etc/localtime && \
    ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

COPY conf/zoo.cfg /zookeeper/conf/


RUN sed -i 's/ZOO_LOG_DIR="."/ZOO_LOG_DIR="\/logs"/' /zookeeper/bin/zkEnv.sh && \
    sed -i 's/ZOO_LOG4J_PROP="INFO,CONSOLE"/ZOO_LOG4J_PROP="INFO,ROLLINGFILE"/' /zookeeper/bin/zkEnv.sh && \
    sed -i 's/zookeeper.root.logger=INFO, CONSOLE/zookeeper.root.logger=INFO,ROLLINGFILE/' /zookeeper/conf/log4j.properties && \
    sed -i 's/zookeeper.log.dir=./zookeeper.log.dir=\/logs/' /zookeeper/conf/log4j.properties

ENV ZOOKEEPER_HOME "/zookeeper"

ENV PATH "$PATH:$ZOOKEEPER_HOME/bin"

COPY start.sh /

RUN chmod 777 /start.sh

EXPOSE 2181 2888 3888

CMD ["/start.sh"]
